import { getScreenList, getIssueList } from '@/api/wtk.js'
import { checkViewIssue } from '@/api/checkView.js'
export default {
	data() {
		return {
			active: 1,
			scrollTop: 0,
			loadMoreStatus: 'more',
			dataList: [],
			page: 1,
			isRefreshing: false,
			model_100: false,
			showScreen: false,
			activeIndex: -1,
			current: -1,
			type: 'timeup',
			filterId: 0,
			collapseItems: [
				{ title: '税法', list: [] },
				{ title: '会计', list: [] },
				{ title: '综合', list: [] },
			],
			tipsMsg: '今日免费次数已用完，请您充值成为会员，以享受更多精彩的功能和服务。',
			showPopup: false,
		};
	},
	methods: {
		jumpSearch() {
			uni.navigateTo({
				url: '/pages/problemBase/search?type=1'
			})
		},

		// 切换浏览量和发布时间
		toggle(e) {
			this.active = e;
			this.type = e == 1 ? 'timeup' : 'hotup'
			this.topBack()
			this.page = 1
			this.getIssueLists()
		},
		onClickScreen() {
			this.showScreen = true
		},
		// 置顶
		topBack() {
			this.scrollTop = 1;
			this.$nextTick(() => {
				this.scrollTop = 0;
			});
		},
		toInfo(id) {
			checkViewIssue({ id }).then(res => {
				if (res.code == -100) {
					this.showPopup = true
				} else {
					uni.navigateTo({
						url: "./details?id=" + id
					})
				}
			})
		},
		//下一页
		loadMore() {
			if (this.loadMoreStatus == 'more') {
				this.page++;
				this.getIssueLists();
			}
		},
		//下拉刷新
		reload() {
			this.page = 1
			this.dataList = []
			this.isRefreshing = true;
			this.getIssueLists()
		},
		// 点击分类tag
		chooseTag(item, index) {
			this.activeIndex = index
			this.active = 1
			this.current = -1
			this.type = 'timeup'
			this.filterId = item.id
			this.showScreen = false
			this.page = 1
			this.dataList = []
			this.getIssueLists()
			this.topBack()
		},

		// 切换分类
		onChange(e) {
			console.log(e, '111111111111111111111');
		},

		/**获取分类**/
		async getScreenList(n) {
			console.log(n, 'n');
			var params = {
				'type': n
			};
			let res = await getScreenList(params)
			uni.hideLoading()
			if (res.code == 1) {
				const index = n === 1 ? 1 : n === 2 ? 0 : 2;
				this.collapseItems[index].list = res.data;
				console.log(this.collapseItems[index], 'this.collapseItems');
			} else {
				this.$tools.showToast(res.msg);
			}
		},

		// 获取列表数据
		async getIssueLists() {
			if (this.page == 1) {
				uni.showLoading({
					title: '加载中',
					position: 'bottom'
				});
			} else {
				this.loadMoreStatus = 'loading';
			}
			var params = {
				page: this.page,
				limit: 10,
				grade_switch: 0,
				cate_id: this.filterId,
				type: this.type
			};
			let res = await getIssueList(params);
			if (this.page == 1) {
				this.dataList = [];
			}
			if (res.code == 1) {
				var newList = res.data;
				if (newList.length >= 10) {
					this.loadMoreStatus = 'more';
				} else {
					this.loadMoreStatus = 'noMore';
				}
				this.dataList = [...this.dataList, ...res.data];
				this.isRefreshing = false;
				uni.hideLoading();
			} else {
				this.$tools.showToast(res.msg);
				this.loadMoreStatus = 'noMore';
			}
		},

		//去开通会员
		goPlatform() {
			uni.navigateTo({
				url: "/pages/my/vip/index"
			})
		}
	},
	onLoad() {
		this.getScreenList(1)
		this.getScreenList(2)
		this.getScreenList(3)
		this.getIssueLists()
	},
};